package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.it;


import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.ItNetworkDevice;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Deprecated
@Repository
public interface ItNetworkDeviceRepo extends JpaRepository<ItNetworkDevice, String> {

    ItNetworkDevice findByAssetId(String assetId);

    @Query(value = "select m from ItNetworkDevice m where 1=1 and (:userid is null OR m.userId = :userid)  order by m.insertTime desc")
    Page<ItNetworkDevice> getNetworkDeviceByUser(Pageable pageable, String userid);


    @Query(value = "select m from ItNetworkDevice m where 1=1 " +
            "and (:userid is null OR m.userId = :userid)  " +
            "and (:assetIp is null OR m.assetIp LIKE CONCAT('%',:assetIp,'%') )  " +
            "and (:brandType is null OR m.brandType LIKE CONCAT('%',:brandType,'%') )  " +
            "and (:brandSys is null OR m.brandSys LIKE CONCAT('%',:brandSys,'%'))  " +
            "and (:brandSn is null OR m.brandSn LIKE CONCAT('%',:brandSn,'%'))  " +
            "and (:capitalTyped is null OR m.capitalTyped LIKE CONCAT('%',:capitalTyped,'%'))  " +
            "and (:brand is null OR m.brand = :brand)  " +
            "and (:capitalType is null OR m.capitalType LIKE CONCAT('%',:capitalType,'%'))  " +
            "order by m.insertTime desc")
    Page<ItNetworkDevice> searchNetworkDeviceByUser(Pageable pageable, String userid, String assetIp, String brandType,
                                                    String brandSys, String brandSn, String capitalTyped, String brand, String capitalType);


    @Query(value = "select a from ItNetworkDevice a where 1=1 "+
            "and ((:ssd is null or asset_Ip like CONCAT('%',:ssd,'%')) " +
            "or (:ssd is null or brand_Sys like CONCAT('%',:ssd,'%')) " +
            "or (:ssd is null or brand_Sn like CONCAT('%',:ssd,'%'))) ")
    List<ItNetworkDevice> searchNetworkSpecial(String ssd);

    @Query(value = "select a from ItNetworkDevice a where 1=1 "+
            "and ((:ssd is null or asset_Ip = :ssd ) " +
            "or (:ssd is null or brand_Sys  = :ssd ) " +
            "or (:ssd is null or brand_Sn   = :ssd )) ")
    List<ItNetworkDevice> searchNetworkSpecialNotLike(String ssd);
}
